package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.SearchService;
import org.elasticsearch.action.search.SearchRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("search")
public class ItermSearchController {
    @Autowired
    SearchService service;

    @PostMapping("list")
    public PageDTO<ItemDoc> getList(@RequestBody RequestParams requestParams){
        SearchRequest request = new SearchRequest("item");
        PageDTO<ItemDoc> pageResult = service.getsearchAll(requestParams,request);
        return pageResult;

    }


    @GetMapping("suggestion")
    public List<String>getSuggestion(@RequestParam("key") String key){
        return service.getSuggestions( key);
    }

    @PostMapping("filters")
    public Map<String,List<String>> getFilters(@RequestBody RequestParams requestParams){

        SearchRequest request = new SearchRequest("item");
        Map<String, List<String>> listMap = service.getFilters(requestParams, request);
        return listMap;
    }






}
